import Vue from 'vue';
import globalLoading from './index.vue';

class Loading {
  modalInstance = null;
  constructor() {
    this.init();
  }
  init () {
    const ModalConstructor = Vue.extend(globalLoading);
    this.modalInstance = new ModalConstructor();
    this.modalInstance.$mount(document.createElement('div'));
    document.body.appendChild(this.modalInstance.$el);
  }
  open() {
    this.modalInstance && this.modalInstance.open();
  }
  close() {
    this.modalInstance && this.modalInstance.close();
  }
  install(Vue) {
    Vue.prototype.$loading = this;
  }
}

export default new Loading();